package com.zb.framework.controller;

import com.zb.framework.api.grpc.HelloRequest;
import com.zb.framework.api.grpc.HelloResponse;
import com.zb.framework.api.grpc.MyServiceGrpc;
import com.zb.zeus.common.core.web.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fujianjian
 * @date 2023/4/21 14:29
 **/
@Slf4j
@RestController
@RequestMapping("/grpc")
public class GrpcDemoController {


    /**
     * <dependency>
     *     <groupId>net.devh</groupId>
     *     <artifactId>grpc-client-spring-boot-starter</artifactId>
     *     <version>2.13.0.RELEASE</version>
     * </dependency>
     */
    @GrpcClient("PROJECT-NAME")
    private MyServiceGrpc.MyServiceBlockingStub myServiceBlockingStub;


    @GetMapping("/greet")
    public AjaxResult greetGrpc(String name) {
        log.info("param:{}", name);
        HelloRequest helloRequest = HelloRequest.newBuilder().setName(name).build();
        HelloResponse helloResponse = myServiceBlockingStub.sayHello(helloRequest);

        return AjaxResult.success("success" + helloResponse.getMessage());

    }
}
